using UnityEngine;
using UnityEngine.SceneManagement;

public struct SpriteRoomInfo
{
	public static SpriteRoomInfo[] objects = new SpriteRoomInfo[0];

	public static SpriteRoomInfo[] tempList = new SpriteRoomInfo[0];

	public int sceneHashCode;

	public int hash;

	public Vector3 position;

	public Quaternion rotation;

	public Sprite sprite;

	public bool flipX;

	public bool flipY;

	public SpriteRoomInfo(SpriteRenderer spriteRender)
	{
		sceneHashCode = SceneManager.GetActiveScene().name.GetHashCode();
		hash = GetHash(spriteRender.transform);
		position = spriteRender.transform.position;
		rotation = spriteRender.transform.rotation;
		sprite = spriteRender.sprite;
		flipX = spriteRender.flipX;
		flipY = spriteRender.flipY;
	}

	public static bool Load(SpriteRenderer spriteRender)
	{
		for (int i = 0; i < objects.Length; i++)
		{
			if (objects[i].hash == GetHash(spriteRender.transform))
			{
				spriteRender.transform.position = objects[i].position;
				spriteRender.transform.rotation = objects[i].rotation;
				spriteRender.sprite = objects[i].sprite;
				spriteRender.flipX = objects[i].flipX;
				spriteRender.flipY = objects[i].flipY;
				return true;
			}
		}
		return false;
	}

	public static void Add(SpriteRenderer spriteRender)
	{
		tempList = objects;
		objects = new SpriteRoomInfo[tempList.Length + 1];
		for (int i = 0; i < tempList.Length; i++)
		{
			objects[i] = tempList[i];
		}
		objects[tempList.Length] = new SpriteRoomInfo(spriteRender);
		tempList = new SpriteRoomInfo[0];
	}

	public static void Reset()
	{
		objects = new SpriteRoomInfo[0];
	}

	public static void ResetCurrentScene()
	{
		for (int i = 0; i < objects.Length; i++)
		{
			if (objects[i].sceneHashCode == SceneManager.GetActiveScene().name.GetHashCode())
			{
				Remove(objects[i]);
				i = 0;
			}
		}
	}

	private static void Remove(SpriteRoomInfo info)
	{
		tempList = objects;
		objects = new SpriteRoomInfo[tempList.Length - 1];
		int num = 0;
		for (num = 0; num < tempList.Length; num++)
		{
			if (tempList[num].hash == info.hash)
			{
				tempList[num] = tempList[tempList.Length - 1];
				break;
			}
		}
		for (num = 0; num < objects.Length; num++)
		{
			objects[num] = tempList[num];
		}
	}

	public static int GetHash(Transform spriteRender)
	{
		return SceneManager.GetActiveScene().name.GetHashCode() + spriteRender.gameObject.name.GetHashCode();
	}
}
